package com.ydd.controller.admin;

import com.ydd.dto.YddAdvposDTO;
import com.ydd.dto.YddAdvposPageDTO;
import com.ydd.entity.YddAdvpos;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.IYddAdvposService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("ydd_advpos")
@Api(tags = "广告位管理接口")
@Slf4j
public class AdvposController {

    @Autowired
    private IYddAdvposService yddAdvposService;

    @GetMapping("/list")
    @ApiOperation("广告位分页查询")
    public Result<PageResult> pageQuery(YddAdvposPageDTO yddAdvposPageDTO){
        log.info("广告位分页查询{}", yddAdvposPageDTO);
        PageResult pageResult = yddAdvposService.pageQuery(yddAdvposPageDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/rowInfo")
    @ApiOperation("广告位详情")
    public Result selectById(Integer id){
        log.info("广告位详情",id);
        YddAdvpos yddAdvpos = yddAdvposService.selectById(id);
        return Result.success(yddAdvpos);
    }

    @PostMapping("/update")
    @ApiOperation("广告位修改")
    public Result update(@RequestBody YddAdvpos yddAdvpos){
        log.info("广告位修改",yddAdvpos);
        yddAdvposService.update(yddAdvpos);
        return Result.success();
    }

    @GetMapping("/all")
    @ApiOperation("广告位查询所有")
    public Result getAll(){
        log.info("查询所有广告位");
        List<YddAdvpos> yddAdvposList = yddAdvposService.findAll();
        return Result.success(yddAdvposList);
    }

    @PostMapping("/add")
    @ApiOperation("添加广告位")
    public Result add(@RequestBody YddAdvposDTO yddAdvposDTO){
        log.info("添加广告位");
        yddAdvposService.add(yddAdvposDTO);
        return Result.success();
    }

    @GetMapping("/del")
    @ApiOperation("删除广告位")
    public Result deleteById(Integer id){
        log.info("删除分类{}",id);
        Boolean flag = yddAdvposService.deleteById(id);
        if(flag){
            return Result.success();
        }else {
            return Result.error("系统默认数据，不允许删除");
        }

    }
}

